***********************************************************************************************************
** This do-file replicates the results in Table B.4 and creates the figures in Section C of the Appendix **
***********************************************************************************************************

* First, please change your directory (using the command cd) to the folder with the dataset ProfileDataset.csv.

import delimited ProfileDataset.csv, clear

* Table B.4 (Weighted regression)

encode province, generate (provinces)

*neighbor
*likert
ebalance respondent_female respondent_education2 respondent_age, manualtargets(0.5 2.8 31.5)

svyset [pweight= _webal]
eststo: svy: reg neighborscale2 female young old arab kurd alawite christian primary middle high university turkishfriends knowsturkish foughtwithasad foughtwithfsa tortured i.provinces

*binary
eststo: svy: logit neighborbinary female young old arab kurd alawite christian primary middle high university turkishfriends knowsturkish foughtwithasad foughtwithfsa tortured i.provinces

*workpermit
**likert
eststo: svy: reg workpermitscale2 female young old arab kurd alawite christian primary middle high university turkishfriends knowsturkish foughtwithasad foughtwithfsa tortured i.provinces

*binary
eststo: svy: logit workpermitbinary female young old arab kurd alawite christian primary middle high university turkishfriends knowsturkish foughtwithasad foughtwithfsa tortured i.provinces

*citizenship
**likert
eststo: svy: reg citizenshipscale2 female young old arab kurd alawite christian primary middle high university turkishfriends knowsturkish foughtwithasad foughtwithfsa tortured i.provinces

*binary
eststo: svy: logit citizenshipbinary female young old arab kurd alawite christian primary middle high university turkishfriends knowsturkish foughtwithasad foughtwithfsa tortured i.provinces



* Figures in Section C

*** generate a variable called 'first' to denote the first observation for each respondent in the dataset 
 
egen first=tag(idnumbernew)

*** Figure C.2 (Respondents' Age)

hist respondent_age if first==1, discrete percent gap(40) color(maroon) note("Number of Respondents: 2,362") title("Respondents' Age") xtitle("Age") plotregion(margin(0 10 1 1)) 

*** Figure C.3 (Respondents' Gender)

replace respondent_female=2 if respondent_female==0

hist respondent_female if first==1, discrete percent gap(40) title("Respondents' Gender") color(maroon) xtitle("") xlabel(1 "Female" 2 "Male") note("Number of Respondents: 2,362") plotregion(margin(0 20 1 1)) 

*** Figure C.4 (Respondents' Age by Gender)

replace respondent_female=0 if respondent_female==2

la def scale_gender 1 "Female" 0 "Male"
la val respondent_female scale_gender
la variable respondent_female Gender

hist respondent_age if first==1, by(respondent_female, title("Respondents' Age by Gender") note("")) discrete percent  color(maroon) note("") title("") xtitle("") xlabel(20(5)70) plotregion(margin(0 1 1 1)) 

*** Figure C.5 (Respondents' Education by Gender)

*** generate a new variable for respondent education to combine the respondents with the same level of education into one category

hist respondent_education2 if first==1, by(respondent_female, title("Respondents' Education by Gender") note("")) discrete percent gap(20) color(maroon) note("") title("") xtitle("") xlabel(1 "University or more" 2 "High School" 3 "Secondary" 4 "Primary" 5 "No education", angle(45)) plotregion(margin(0 1 1 1)) 

*** Figure C.6 (Respondents' Occupation)

*** generate a new variable for respondent occupation to combine the respondents with the same type of occupation into one category

gen respondent_occupation_short=11
* unemployed
replace respondent_occupation_short=1 if respondent_occupation==1 | respondent_occupation==2 
* housewife
replace respondent_occupation_short=2 if respondent_occupation==3 | respondent_occupation==4 
* student
replace respondent_occupation_short=3 if respondent_occupation==5  
* worker (including foreman)
replace respondent_occupation_short=4 if respondent_occupation==6 | respondent_occupation==7 | respondent_occupation==8 | respondent_occupation==25 | respondent_occupation==26 
* civil servant
replace respondent_occupation_short=5 if respondent_occupation==9  
* manager
replace respondent_occupation_short=6 if respondent_occupation==10 | respondent_occupation==11 | respondent_occupation==12 | respondent_occupation==13 
* army member
replace respondent_occupation_short=7 if respondent_occupation==14 | respondent_occupation==15
* white collar (including mobile independent)
replace respondent_occupation_short=8 if respondent_occupation==16 | respondent_occupation==18 | respondent_occupation==24
* farmer
replace respondent_occupation_short=9 if respondent_occupation==17  
* shop/factory owner
replace respondent_occupation_short=10 if respondent_occupation==19 | respondent_occupation==20 | respondent_occupation==21 | respondent_occupation==22 | respondent_occupation==23

hist respondent_occupation_short if first==1, discrete percent gap(40) color(maroon) note("Number of Respondents: 2,362") title("Respondents' Occupation") xtitle("") ///
xlabel (1 "Unemployed" 2 "Housewife" 3 "Student" 4 "Worker" 5 "Civil servant" 6 "Manager" 7 "Army" 8 "White collar" 9 "Farmer" 10 "Shop/factory owner" 11 "N/A", angle(45)) plotregion(margin(0 10 1 1)) 

*** Figure C.7 (Which party did you vote for in last elections?)

hist respondent_party if first==1, discrete percent gap(40) title("Which party did you vote for in last elections?") color(maroon) xtitle("") xlabel(1 "AKP" 2 "CHP" 3 "MHP" 4 "HDP" 5 "Iyi Parti" 6 "Other" 7 "Didn't vote" 8 "N/A") ///
note("Number of Respondents: 2,362") plotregion(margin(0 10 1 1)) 

*** Figure C.8 (Respondents by province)

rename qil provincenumber

graph bar (count) provincenumber if first==1, over(province, label(angle(45))) ytitle("") title("Respondents by province")




